package com.ithuangyl.common.net;

import com.ithuangyl.common.config.ConfigKeys;
import com.ithuangyl.common.config.Latte;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * author : itHuang
 * e-mail : ithuangyl@163.com
 * date   : 2020/7/15 21:44
 */
public class RestCreator {


    public static final OkHttpClient.Builder HTTP_BUILDER = new OkHttpClient.Builder();

    private void a() {

    }

    private static class OkHttpClientHolder {
        public static final OkHttpClient OK_HTTP_CLIENT = HTTP_BUILDER.build();

    }

    private static class RetrofitHolder {
        private static String baseUrl = Latte.getConfiguration(ConfigKeys.IS_DEBUG) ? Latte.getConfiguration(ConfigKeys.DEBUG_API_HOST) : Latte.getConfiguration(ConfigKeys.RELEASE_API_HOST);
        public static final Retrofit RETROFIT = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .client(OkHttpClientHolder.OK_HTTP_CLIENT)
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();
    }

    public static RestService getService() {
        return RetrofitHolder.RETROFIT.create(RestService.class);
    }
}
